package org.example;

import java.sql.SQLOutput;
import java.util.Scanner;

public class StudentService {
    //学生不超过50个
    private Student[] students = new Student[50];
    private Scanner input = new Scanner(System.in);
    public boolean addStudent(){
        System.out.println("请您输入学生的学号：");
        int stuNo = input.nextInt();
        System.out.println("请您输入学生的姓名：");
        String name = input.next();
        System.out.println("请您输入学生的年龄：");
        int stuAge = input.nextInt();
        System.out.println("请您输入学生的性别：");
        String gender = input.next();
        Student stu = new Student(stuNo,name,stuAge,gender);
        for(int i=0;i<students.length;i++){
            if(students[i]==null){
                students[i] = stu;
                break;
            }
        }
        return true;
    }
    public void showAll(){
        System.out.println("学号\t姓名\t年龄\t性别");
        for(Student stu:students){
            if(stu==null){
                break;
            }
            System.out.println(stu.getId()+"\t"+stu.getName()+"\t"+stu.getAge()+"\t"+stu.getGender());
        }
    }

    public boolean deleteStu(int stuNo){
        int i=0;
        for(;i<students.length;i++){
            if(students[i]==null){
                return false;
            }
            if(students[i].getId()==stuNo){
                break;
            }
        }
        for(;i<students.length;i++){
            if(i+1<students.length) {
                students[i] = students[i + 1];
            }else{
                students[i] = null;
            }
        }
        return true;
    }
}
